package com.wbpay.sdkdemo;

import android.annotation.SuppressLint;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;

public class ScaleUtils {

    public static void init(final View view) {
        final Animation scaleIn = new ScaleAnimation(1.0f, 0.9f, 1.0f, 0.9f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
        scaleIn.setDuration(100);
        scaleIn.setFillAfter(true);
        scaleIn.setInterpolator(view.getContext(),
                android.R.anim.decelerate_interpolator);
        final Animation scaleOut = new ScaleAnimation(0.9f, 1.0f, 0.9f, 1.0f,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
                0.5f);
        scaleOut.setDuration(100);
        scaleOut.setFillAfter(true);
        scaleOut.setInterpolator(view.getContext(),
                android.R.anim.decelerate_interpolator);
        view.setOnTouchListener(new OnTouchListener() {
            @SuppressLint("ClickableViewAccessibility")
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    view.startAnimation(scaleIn);
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    view.startAnimation(scaleOut);
                }
                return false;
            }
        });
    }
}
